<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container >
      <a-form :form="form" slot="detail" v-if='model.bpmStatus === "3" && model.isArchive === "N"' class='e-edit'>
        <a-row>
          <a-col :span="8" >
            <a-form-item label="签订日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择签订日期" v-decorator="['signDate', validatorRules.signDate]" :trigger-change="true" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="是否归档" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-switch v-decorator="['isArchive', validatorRules.isArchive]" ></j-switch>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="归档文件" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-upload v-decorator="['archiveFile', validatorRules.archiveFile]" :trigger-change="true"  ></j-upload>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>

    <a-row v-if="showFlowSubmitButton" style="text-align: center;width: 100%;margin-top: 16px;"><a-button @click="handleOk" type='primary'>提 交</a-button></a-row>
  </a-spin>
</template>

<script>

import pick from 'lodash.pick'
import { getAction } from '@/api/manage'
import { FormTypes,getRefPromise } from '@/utils/JEditableTableUtil'
import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'ContractSaleForm',
  mixins: [JEditableTableMixin],
  components: {
  },
  data() {
    return {
      model:{
        
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      labelCol2: {
        xs: { span: 24 },
        sm: { span: 2 },
      },
      wrapperCol2: {
        xs: { span: 24 },
        sm: { span: 22 },
      },
      // 新增时子表默认添加几行空数据
      addDefaultRowNum: 1,
      validatorRules: {
        archiveFile: {
          rules: [
            { required: true, message: '请上传归档文件!' }
          ]
        },
        isArchive: {
          rules: [
            { required: true, message: '请选择归档状态!' }
          ]
        },
        signDate: {
          rules: [
            { required: true, message: '请输入签订日期!' }
          ]
        },
      },
      url: {
        add: "/contract/contractSale/add",
        edit: "/contract/contractSale/edit",
        queryById: "/contract/contractSale/queryById",
        contractSalePaymentCollection: {
          list: '/contract/contractSale/queryContractSalePaymentCollectionByMainId'
        },
      },
      fields:[
        'projectName','isArchive','archiveFile'
      ]
    }
  },
  props: {
    //流程表单data
    formData: {
      type: Object,
      default: ()=>{},
      required: false
    },
    //表单模式：false流程表单 true普通表单
    formBpm: {
      type: Boolean,
      default: false,
      required: false
    },
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  computed: {
    formDisabled(){
      if(this.formBpm===true){
        if(this.formData.disabled===false){
          return false
        }
        return true
      }
      return this.disabled
    },
    showFlowSubmitButton(){
      if(this.formBpm===true){
        if(this.formData.disabled===false){
          return true
        }
      }
      return false
    }
  },
  created () {
    //如果是流程中表单，则需要加载流程表单data
    this.showFlowData();
  },
  methods: {
    /** 调用完edit()方法之后会自动调用此方法 */
    editAfter() {
      let fieldval = pick(this.model,this.fields)
      this.$nextTick(() => {
        this.form.setFieldsValue(fieldval)
      })
    },
    /** 整理成formData */
    classifyIntoFormData(allValues) {
      let main = Object.assign(this.model, allValues.formValue)
      return {
        ...main, // 展开
        contractSalePaymentCollectionList: allValues.tablesValue[0].values,
      }
    },
    //渲染流程表单数据
    showFlowData(){
      if(this.formBpm === true){
        let params = {id:this.formData.dataId};
        getAction(this.url.queryById,params).then((res)=>{
          if(res.success){
            this.edit (res.result);
          }
        })
      }
    },
    validateError(msg){
      this.$message.error(msg)
    },
    popupCallback(row){
      this.form.setFieldsValue(pick(row,this.fields))
    },
  }
}
</script>
<style scoped>
/* .e-edit{
  disabled: disabled;
} */
</style>